//
//  SandBoxHandler.m
//  UI15_SandBox_NSFileManager_NSFileHandler
//
//  Created by 李劲成 on 16/3/29.
//  Copyright © 2016年 ljc. All rights reserved.
//

#import "SandBoxHandler.h"

@implementation SandBoxHandler

#pragma mark - Creating and Init

+ (instancetype) sandBoxHandler {
    SandBoxHandler *sand = [[SandBoxHandler alloc]init];
    return sand;
}


#pragma mark - path

/** 获取 app的 Sandbox 路径. */
- (NSString *) pathForAppSandbox {
    
    // 核心 API: 函数 NSHomeDirectory
    return NSHomeDirectory();
    
}

/** 获取 Documents 路径 */
+ (NSString *)pathOfDoucuments {
    // 核心 API.NSSearchPathForDirectoriesInDomains
    return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
}

- (NSString *)pathForDoucuments {
    return [SandBoxHandler pathOfDoucuments];
}

/** 向 Documents 路径 保存的文件名 */
+ (NSString *)saveInDocumentsWithFileName:(NSString *)fileName {
    return [[SandBoxHandler pathOfDoucuments]stringByAppendingPathComponent:fileName];
}

/** 获取 Tmp 路径 */
- (NSString *) pathForTmp {
    
    return NSTemporaryDirectory();
}

/** 获取 Library 路径. */
- (NSString *) pathForLibrary {
    
    NSArray *arrOfLibiray = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    
    return arrOfLibiray[0];
}

/** 获取 Caches 路径. */
- (NSString *) pathForCaches {
    NSArray *arrOfCaches = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    return arrOfCaches[0];
    
}

/** 获取 Preferences 路径. */
- (NSString *) pathForPreferences {
    
    return [[self pathForLibrary]stringByAppendingPathComponent:@"Preferences"];
    
}

/** 获取 APP 包路径. */
- (NSString *) pathForApp {
    return [NSBundle mainBundle].resourcePath;
}

@end
